module MyObservable
	def add_observer(&obs)
		@observers_list = [] unless defined? @observers_list
		@observers_list << obs 
	end

	def count_observers
		return 0 unless defined? @observers_list
		@observers_list.size
	end

	def notify(*args)
		@observers_list.each {|o| o.call(*args)} if defined? @observers_list
	end
end

class ObservableClass; include MyObservable; end

module ObservableField	
	def observable_field(*fields)
		for field in fields
			module_eval %(
				def #{field.to_s}
					@#{field.to_s} ||= ObservableClass.new
				end
			)
		end
	end
end


